package dm.ast.model.gen;

import dm.ast.DmConstant;
import dm.ast.DmConstant.*;
import dm.ast.DmDataType;
import dm.ast.model.gen.factory.BaseModelFactory;
import test.utility.Randomly;

public class DmConstantGen extends BaseModelFactory {
    public static DmConstant gen(DmDataType rtype){
        DmConstant dmc;
        if(rtype == null){
            dmc = new NullDmConst();
        } else {
            switch (rtype){
                case INT:
                    dmc = new IntDmConst(r.getLong(-1000 , 1000));
                    break;
                case CHAR:
                    dmc = new StringDmConst(r.getString());
                    break;
                case BINARY:
                    dmc = new BinaryDmConst(r.getString());
                    break;
                case TIME:
                    dmc = new TimeDmConst(r.getLong(0 , System.currentTimeMillis()));
                    break;
                case INTERVAL:
                    dmc = new IntervalDmConst((int) Randomly.getNotCachedInteger(1 , 10));
                    break;
                case CLOB:
                    dmc = new ClobDmConst(r.getString());
                    break;
                case BLOB:
                    dmc = new BlobDmConst(r.getString());
                    break;
                case BOOLEAN:
                    dmc = new BooleanDmConst(Randomly.getBoolean());
                    break;
                default:
                    throw new AssertionError(rtype);
            }
        }
        return dmc;
    }
}
